// JavaScript Document

$(function () {
    $("#accordion").accordion({ active: -1 });
	$('#accordion h3 a').click(function(){		
		var tmp=$(this).parent().next().html();
		var tm=$(tmp).children('li:first').html();
		var t=$(tm).attr('href');
		//var s=t.replace("~/../","");		
		//window.location.replace(s);
	});
});

function Ajax(url, postData, callback){
	$.ajax({				 
		type: 'POST',
		data: postData,
		url: 'ajax.aspx?type=' + url + '&rnd=' + Math.random(),
		success: function(data) {
			callback(data);
		}
	});
}

function Redirect(url){
	window.location.replace(url);
}

function ChangeLanguage(lang){
	Ajax('language', 'code=' + lang, function(data){ window.location.reload(); });
}

function LogOut(){
	Ajax('logout', '', function(data){ Redirect("login.aspx"); });
}

function AjaxResult(url, postData, success, error, isreload, callback){
	Ajax(url, postData, function(data){
		if (data.indexOf('OK') != -1){
			$('#errorAjax').removeClass('editError');
			$('#errorAjax').addClass('result');
			$('#errorAjax img').attr('src', '~/../images/ok.png');
			$('#result-message').html(success);
			$("#errorAjax").show();
			$("#errorAjax").effect("bounce", {}, 200, function(){ $("#errorAjax").hide(); $("#editForm")[0].reset(); if (isreload) location.reload(); else if (callback != null) callback(); });			
		}
		else {
			$('#errorAjax').removeClass('result');
			$('#errorAjax').addClass('editError');
			$('#errorAjax img').attr('src', '~/../images/error.png');
			$('#result-message').html(error);
			$("#errorAjax").show();
			$("#errorAjax").effect("bounce", {}, 200, function(){ $("#errorAjax").hide(); });
		}
	});
}
